package com.testDemo.hutool;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.Digester;
import cn.hutool.system.oshi.OshiUtil;
import org.junit.jupiter.api.Test;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HardwareAbstractionLayer;

import java.util.List;

public class OshiUtilTest {

    @Test
    public void getHardware(){
        HardwareAbstractionLayer hardware = OshiUtil.getHardware();
        System.out.println(hardware);
    }

    public static void main(String[] args) {
        HardwareAbstractionLayer hardware = OshiUtil.getHardware();
        // 获取CPU信息
        CentralProcessor processor = hardware.getProcessor();
        String cpuSerial = processor.getProcessorIdentifier().getProcessorID(); // 获取CPU序列号（在某些系统上可能返回空）
        System.out.println("CPU Serial: " + cpuSerial);

        // 获取硬盘信息
        List<HWDiskStore> diskStores = hardware.getDiskStores();
        if (!diskStores.isEmpty()) {
            HWDiskStore diskStore = diskStores.get(0); // 获取第一个硬盘信息
            String serialNumber = diskStore.getSerial(); // 获取硬盘序列号（在某些系统上可能返回空）
            System.out.println("Disk Serial: " + serialNumber);

            // 组合CPU序列号和硬盘序列号作为机器码（示例）
            String machineCode = cpuSerial + "_" + serialNumber;
            System.out.println("Machine Code: " + machineCode);
            String digestHex =  DigestUtil.md5Hex(machineCode);
            System.out.println("Machine Code MD5: " + digestHex);//6d7c51a55f5826576dbc3655a046a6aa

        } else {
            System.out.println("No disks found.");
        }
    }
}
